//
//  MainSearchViewController.m
//  MINFOBBS
//
//  Created by juvid on 13-11-18.
//  Copyright (c) 2013年 minfo. All rights reserved.
//

#import "MainSearchViewController.h"
#import "DetectionSystemVersion.h"
#import "CustomCell.h"
#import "SBJson.h"
#import "NSMutableArr.h"
#import "UIImageView+WebCache.h"
#import "JokeController.h"
#import "WebController.h"
#import "ConstellationController.h"
#import "UIColor+expanded.h"
#import "ConstellationSingle.h"
#import "SongListConer.h"
#import "LyricsDetail.h"
#import "TrainQuery.h"
#import "TrainTrainsHalf.h"
#import "TrainStation.h"
#import "FinancialParities.h"
#import "FinancialInterest.h"
#import "MovieDetail.h"
#import "MovieRoleOfOne.h"
#import "MovieSong.h"
#import "WeatherViewController.h"
#import "WeatherIndexViewController.h"
#import "TicketListViewController.h"
#import "DoubleBallViewController.h"
#import "MovieShowViewController.h"
#import "NetHelp.h"
@interface MainSearchViewController (){
    float keyHight;
    BOOL isHideView;
    BOOL isOver;
       BOOL isUp;
    NSString *strKeyWord;
    NSArray *arrMessageContent;
    NSString *strNumber;
}
typedef enum {
    MainSearchPanDirectionNone,
    MainSearchPanDirectionUp,
    MainSearchPanDirectionDown
} MainSearchPanDirection;
@property (nonatomic, assign) CGPoint panGestureOrigin;
@property (nonatomic, assign) CGFloat panGestureVelocity;
@property (nonatomic, assign) MainSearchPanDirection panDirection;
@end

@implementation MainSearchViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.navigationItem setHidesBackButton:YES];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    if ([[DetectionSystemVersion alloc]Version]) {
        self.edgesForExtendedLayout=UIRectEdgeNone;
//        self.navigationController.navigationBar.translucent = NO;
    }
    pageLimit=4;
    pageStart=0;
    arrCellContent=[[NSMutableArray alloc]init];
    arrCellHight=[[NSMutableArray alloc]init];
    arrCurrentRow=[[NSMutableArray alloc]init];
     arrHistory=[[NSMutableArray alloc]init];
    if ([Common GetHistorySearch]) {
        arrHistory=[Common GetHistorySearch];
    }
   self.tabel.backgroundColor=[UIColor colorWithRed:243/255.0 green:243/255.0 blue:243/255.0 alpha:1];
    [self SetAllView];
    [self BackButton];
    [self ShareButton];
    [self SetMessageView];
   
    
    if (self.isUrl!=0) {
        [self WebUrl];
    }
    else{
        
        [self GetDatas:self.strSearch];
    }
    // Do any additional setup after loading the view from its nib.
}
-(void)viewDidAppear:(BOOL)animated{
    self.vieDown.hidden=NO;
    if (!isUp) {
        self.vieDown.frame=CGRectMake(0, self.vieDown.frame.origin.y-self.tabelDown.frame.size.height, self.vieDown.frame.size.width, self.vieDown.frame.size.height);
        isUp=YES;
    }
     keyHight=self.view.frame.origin.y;
}
-(void)viewWillAppear:(BOOL)animated{
//     [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"barHeadImage"] forBarMetrics:UIBarMetricsDefault];
    
}
- (void)viewWillDisappear:(BOOL)animated{
     [Common SetHistorySearch:arrHistory];
    [tRequest clearDelegatesAndCancel];
    [tRequest cancel];
    [NSObject cancelPreviousPerformRequestsWithTarget:self];
    [NSThread cancelPreviousPerformRequestsWithTarget:self];
}
-(void)WebUrl{
    NSMutableArray *mlArr=[[NSMutableArray alloc]init];
    NSMutableDictionary *mlDic=[[NSMutableDictionary alloc]init];
    NSURL *url= [NSURL URLWithString:self.strSearch];
//    NSLog(@"%@",self.strSearch);
    float rowHight=620;
    if (self.isUrl==1) {
        [mlDic setObject:@"号码" forKey:@"name"];
    }
    else{
        [mlDic setObject:@"推荐" forKey:@"name"];
        if (self.isUrl==2) {
            rowHight=430;
        }
        else if(self.isUrl==5)
        {
            rowHight=75*6;
            [mlDic setObject:@"商家" forKey:@"name"];
        }
        
        
    }
    [mlDic setObject:@"" forKey:@"Title"];
    UIWebView *webContent=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 296,rowHight)];
    webContent.delegate = self;
    webContent.alpha=0.9999;
    //                [webContent setScalesPageToFit:YES];
    [webContent sizeToFit];
    [(UIScrollView *)[[webContent subviews] objectAtIndex:0] setBounces:NO];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [webContent loadRequest:request];
    [mlDic setObject:webContent forKey:@"content"];
    webContent=Nil;
    rowHight=rowHight+32;
    [mlArr addObject:mlDic];
    [arrCellContent addObject:mlArr];
    NSArray *arrHight=[[NSArray alloc]initWithObjects:[NSString stringWithFormat:@"%f",rowHight], nil];
    [arrCurrentRow addObject:[NSString stringWithFormat:@"%d",0]];
    [arrCellHight addObject:arrHight];
    [self TableReloadData];
}
-(void)TableReloadData{
    [self.tabel reloadData];
    if (arrCellContent.count>0) {
        NSIndexPath *lastIndexPath = [NSIndexPath indexPathForRow:0 inSection:arrCellContent.count-1];
        [self.tabel scrollToRowAtIndexPath:lastIndexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
    }
  
}
#pragma mark 异步数据请求
-(void)GetDatas:(NSString *)query{
    [self BtnRow:query];
    self.txtContent.text=query;
    tRequest=[[[ScreenAccess alloc]init]ASIGetSearch:query Start:pageStart Limit:pageLimit];
    [tRequest setDelegate:self];
    [tRequest setUsername:@"allMessage"];
}
-(void)requestFinished:(ASIHTTPRequest*)request{
    NSString *response = [request responseString];
    SBJsonParser * parser = [[SBJsonParser alloc] init];
    NSMutableDictionary *Result = [parser objectWithString:response];
    if ([request.username isEqual:@"allMessage"]){
//        BOOL IsSuccess=[[[Result objectForKey:@"Response"]objectForKey:@"status"]integerValue]==200?YES:NO;
        int status=[[[Result objectForKey:@"Response"]objectForKey:@"status"]integerValue];
        if (status==200) {
//            if (arrReturn==nil) {
//                arrReturn=[[NSMutableArray alloc]init];
//            }
//            [arrReturn addObject:[[Result objectForKey:@"Response"] objectForKey:@"Categories"]];
//            [self AddCellHight];
            [self AddCellHight:[[[Result objectForKey:@"Response"] objectForKey:@"Categories"] objectForKey:@"Category"]];
             [arrHistory addObject:self.txtContent.text];
        }
        else if(status==404){
            [self NetHelp];
        }
    }
}
-(void)NetHelp{
    NSMutableArray *mlArr=[[NSMutableArray alloc]init];
     NSMutableDictionary *mlDic=[[NSMutableDictionary alloc]init];
    [mlDic setObject:@"互联网帮助" forKey:@"name"];
     [mlDic setObject:self.txtContent.text forKey:@"Title"];
    [mlArr addObject:mlDic];
    [arrCellContent addObject:mlArr];
    NSArray *arrHight=[[NSArray alloc]initWithObjects:[NSString stringWithFormat:@"%f",118.0], nil];
    [arrCellHight addObject:arrHight];
    [arrCurrentRow addObject:[NSString stringWithFormat:@"%d",0]];
    mlDic=Nil;
    mlArr=Nil;
    arrHight=Nil;
    [self TableReloadData];
}
-(void)AddCellHight:(NSArray *)arrObject{
//    NSArray *arr=[[arrReturn objectAtIndex:arrReturn.count-1] objectForKey:@"Category"];
    NSArray *arr=arrObject;
    [arrCurrentRow addObject:[NSString stringWithFormat:@"%d",0]];
    NSMutableArray *mlArr=[[NSMutableArray alloc]init];
    NSMutableArray *arrHight=[[NSMutableArray alloc]init];
    int rowCount=arr.count;
    if (rowCount>4) {
        rowCount=4;
    }
    for (int j=0; j<rowCount; j++) {
        float rowHight=0.0;
        NSMutableDictionary *mlDic=[[NSMutableDictionary alloc]init];
        if ([[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"joke"]||[[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"riddle"]||[[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"greeting"]) {
            JokeController *cusChannel=[[JokeController alloc]init];
            cusChannel.arrReturn=[[[arr objectAtIndex:j] objectForKey:@"Items"] objectForKey:@"Item"];
            cusChannel.isSelf=YES;
            cusChannel.strKey=self.txtContent.text;
//            NSLog(@"%@",self.txtContent.text);
            if ([[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"joke"]) {
                [mlDic setObject:@"笑话" forKey:@"name"];
                [mlDic setObject:@"开心一刻" forKey:@"Title"];
            }
            else if ([[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"greeting"]){
                [mlDic setObject:@"祝福" forKey:@"name"];
                [mlDic setObject:@"传递浓情祝福" forKey:@"Title"];
            }
            else if([[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"riddle"]){
                [mlDic setObject:@"谜语" forKey:@"name"];
                [mlDic setObject:self.txtContent.text forKey:@"Title"];
                cusChannel.isRidele=YES;
            }
            
            cusChannel.view.frame=CGRectMake(0, 0, 296, 200);
            rowHight=cusChannel.tableView.contentSize.height;
            cusChannel.view.frame=CGRectMake(0, 32, 296, rowHight);
            [mlDic setObject:cusChannel forKey:@"content"];
            cusChannel=Nil;
                   }
        else if ([[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"knowledge"]){
            [mlDic setObject:@"百科" forKey:@"name"];
            [mlDic setObject:@"百科小知识" forKey:@"Title"];
            NSString *str=[[[[[[[[arr objectAtIndex:j] objectForKey:@"Items"] objectForKey:@"Item"] objectAtIndex:0]objectForKey:@"Properties"] objectForKey:@"Property"] objectAtIndex:0] objectForKey:@"text"];
            CGSize sizeFrame=[DetectionSystemVersion String:str Width:270 Font:15];
            rowHight=sizeFrame.height;
            UILabel *lab=[[UILabel alloc]initWithFrame:CGRectMake(13, 42, 270, rowHight)];
            rowHight=rowHight+20;
            lab.font=[UIFont systemFontOfSize:15];
            lab.text=str;
            lab.numberOfLines=0;
            lab.textColor=[UIColor colorWithHexString:@"0x4a4a4a"];
            [mlDic setObject:lab forKey:@"content"];
        }
        else if ([[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"weather"]){
            [mlDic setObject:@"天气" forKey:@"name"];
            if ([[[arr objectAtIndex:j]objectForKey:@"Entrance"]isEqual:@"Weather.GetWeatherForBot"]) {
                //取城市
                NSMutableArray *tempArray=[[[arr objectAtIndex:j] objectForKey:@"Items"] objectForKey:@"Item"];
                NSArray *tempList=[[[tempArray objectAtIndex:0] objectForKey:@"Properties"] objectForKey:@"Property"];
                NSString *tempCity=[[tempList objectAtIndex:8] objectForKey:@"text"];
                
                 [mlDic setObject:tempCity forKey:@"Title"];
                WeatherViewController *cusChannel=[[WeatherViewController alloc]init];
                cusChannel.arrReturn=[arr objectAtIndex:j];
                rowHight=400;
                cusChannel.view.frame=CGRectMake(0, 32, 296, rowHight);
                [mlDic setObject:cusChannel forKey:@"content"];
                cusChannel=Nil;

            }
            else if([[[arr objectAtIndex:j]objectForKey:@"Entrance"]isEqual:@"Weather.GetWeatherPoints"]){
                [mlDic setObject:@"天气指数" forKey:@"Title"];
                WeatherIndexViewController *cusChannel=[[WeatherIndexViewController alloc]init];
                cusChannel.arrReturn=[[[[[[arr objectAtIndex:j] objectForKey:@"Items"] objectForKey:@"Item"]objectAtIndex:0] objectForKey:@"Properties"] objectForKey:@"Property"];
                cusChannel.isSelf=YES;
                rowHight=190;
                cusChannel.view.frame=CGRectMake(0, 32, 296, rowHight);
                [mlDic setObject:cusChannel forKey:@"content"];
                cusChannel=Nil;
                
            }
           
            
        }
        else if ([[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"lotto"]){
            [mlDic setObject:@"彩票" forKey:@"name"];
            if ([[[arr objectAtIndex:j]objectForKey:@"Entrance"]isEqual:@"Lotto.GetLotto"]) {
                NSArray *arr1=[[[arr objectAtIndex:j] objectForKey:@"Items"] objectForKey:@"Item"];
                if (arr1.count==1) {
                    NSString *lottoName=[[arr1 objectAtIndex:0] objectForKey:@"Title"];
                    
                     [mlDic setObject:lottoName forKey:@"Title"];
                    DoubleBallViewController  *cusChannel=[[DoubleBallViewController alloc]init];
                    cusChannel.doubleBalls=[[[arr objectAtIndex:j] objectForKey:@"Items"] objectForKey:@"Item"];
                    cusChannel.isSelf=YES;
                    rowHight=176;
                    cusChannel.view.frame=CGRectMake(0, 32, 296, rowHight);
                    [mlDic setObject:cusChannel forKey:@"content"];
                    cusChannel=Nil;

                }
                else{
                [mlDic setObject:@"热门彩票近期开奖信息" forKey:@"Title"];
                TicketListViewController *cusChannel=[[TicketListViewController alloc]init];
                cusChannel.arrReturn=[[[arr objectAtIndex:j] objectForKey:@"Items"] objectForKey:@"Item"];
                rowHight=8*44;
                cusChannel.view.frame=CGRectMake(0, 32, 296, rowHight);
                [mlDic setObject:cusChannel forKey:@"content"];
                cusChannel=Nil;
                }
                
            }
            
        }
        else if ([[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"movieshow"]){
            [mlDic setObject:@"电影" forKey:@"name"];
            if ([[[arr objectAtIndex:j]objectForKey:@"Entrance"]isEqual:@"MovieShow.SearchMovieShow"]) {
                    [mlDic setObject:@"电影演出" forKey:@"Title"];
                    MovieShowViewController *cusChannel=[[MovieShowViewController alloc]init];
                    cusChannel.movieShowArray=[[[arr objectAtIndex:j] objectForKey:@"Items"] objectForKey:@"Item"];
                cusChannel.isSelf=YES;
                cusChannel.query=self.txtContent.text;
                    rowHight=4*40+38;
                    cusChannel.view.frame=CGRectMake(0, 32, 296, rowHight);
                    [mlDic setObject:cusChannel forKey:@"content"];
                    cusChannel=Nil;
               
            }
            
        }

        else if ([[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"tvserials"]){
            [mlDic setObject:@"影视" forKey:@"name"];
            [mlDic setObject:@"影视剧情" forKey:@"Title"];
            if ([[[arr objectAtIndex:j]objectForKey:@"Entrance"]isEqual:@"TVSerials.TvsSearch_MovieDetail"]) {
                NSString *str=[[[[[[[[arr objectAtIndex:j] objectForKey:@"Items"] objectForKey:@"Item"] objectAtIndex:0]objectForKey:@"Properties"] objectForKey:@"Property"] objectAtIndex:0] objectForKey:@"text"];
                CGSize sizeFrame=[DetectionSystemVersion String:str Width:270 Font:15];
                rowHight=sizeFrame.height;
                UILabel *lab=[[UILabel alloc]initWithFrame:CGRectMake(13, 42, 270, rowHight)];
                rowHight=rowHight+20;
                lab.font=[UIFont systemFontOfSize:15];
                lab.text=str;
                lab.numberOfLines=0;
                lab.textColor=[UIColor colorWithHexString:@"0x4a4a4a"];
                [mlDic setObject:lab forKey:@"content"];
            }
            else if([[[arr objectAtIndex:j]objectForKey:@"Entrance"]isEqual:@"TVSerials.TvsSearch_TvDetail"]){
                MovieDetail *cusChannel=[[MovieDetail alloc]init];
                cusChannel.arrReturn=[arr objectAtIndex:j];
                cusChannel.isSelf=YES;
                rowHight=195;
                if ([[[arr objectAtIndex:j] objectForKey:@"Links"] isEqual:[NSNull null]]) {
                    cusChannel.isMovie=YES;
                    rowHight=150;
                }
                cusChannel.view.frame=CGRectMake(0, 32, 296, rowHight);
                [mlDic setObject:cusChannel forKey:@"content"];
                cusChannel=Nil;
                
            }
            else if([[[arr objectAtIndex:j]objectForKey:@"Entrance"]isEqual:@"TVSerials.TvsSearch_SingleRole1"]){
                MovieRoleOfOne *cusChannel=[[MovieRoleOfOne alloc]init];
                cusChannel.arrReturn=[arr objectAtIndex:j];
                rowHight=94;
                cusChannel.view.frame=CGRectMake(0, 32, 296, rowHight);
                [mlDic setObject:cusChannel forKey:@"content"];
                cusChannel=Nil;
                
            }
        }
        else if ([[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"lyrics"]){
            [mlDic setObject:@"歌词" forKey:@"name"];
            [mlDic setObject:@"歌 曲" forKey:@"Title"];
            
            if ([[[arr objectAtIndex:j]objectForKey:@"Entrance"]isEqual:@"Lyrics.GetNameBySingerForBot"]) {
                SongListConer *cusChannel=[[SongListConer alloc]init];
                cusChannel.arrReturn=[[[arr objectAtIndex:j] objectForKey:@"Items"] objectForKey:@"Item"];
                cusChannel.isSelf=YES;
                cusChannel.strKey=self.txtContent.text;
                rowHight=73;
                cusChannel.view.frame=CGRectMake(0, 32, 296, rowHight);
                [mlDic setObject:cusChannel forKey:@"content"];
                cusChannel=Nil;
                
            }
            else if([[[arr objectAtIndex:j]objectForKey:@"Entrance"]isEqual:@"Lyrics.GetLyrics"]){
                LyricsDetail *cusChannel=[[LyricsDetail alloc]init];
                cusChannel.arrReturn=[[[[arr objectAtIndex:j] objectForKey:@"Items"] objectForKey:@"Item"] objectAtIndex:0];
                cusChannel.isSelf=YES;
                rowHight=225;
                cusChannel.view.frame=CGRectMake(0, 32, 296, rowHight);
                [mlDic setObject:cusChannel forKey:@"content"];
                cusChannel=Nil;
                
            }
            else if([[[arr objectAtIndex:j]objectForKey:@"Entrance"]isEqual:@"Lyrics.GetLyricsByTVName"]){
                MovieSong *cusChannel=[[MovieSong alloc]init];
                cusChannel.arrReturn=[[[arr objectAtIndex:j] objectForKey:@"Items"] objectForKey:@"Item"];
                cusChannel.isSelf=YES;
                rowHight=cusChannel.arrReturn.count*60;
                cusChannel.view.frame=CGRectMake(0, 32, 296, rowHight);
                [mlDic setObject:cusChannel forKey:@"content"];
                cusChannel=Nil;
                
            }

        }
        else if ([[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"exchange"]){
            [mlDic setObject:@"汇率" forKey:@"name"];
            
            if ([[[arr objectAtIndex:j]objectForKey:@"Entrance"]isEqual:@"Exchange.GetExchange"]) {
                [mlDic setObject:@"汇率详情" forKey:@"Title"];
                FinancialParities *cusChannel=[[FinancialParities alloc]init];
              cusChannel.pageLimit=[[[[arr objectAtIndex:j] objectForKey:@"Items"] objectForKey:@"total"] integerValue]-4;
                cusChannel.strKey=self.txtContent.text;
                cusChannel.arrReturn=[[[arr objectAtIndex:j] objectForKey:@"Items"] objectForKey:@"Item"];
                rowHight=(cusChannel.pageLimit+5)*60;
                cusChannel.view.frame=CGRectMake(0, 32, 296, rowHight);
                [mlDic setObject:cusChannel forKey:@"content"];
                cusChannel=Nil;
                
            }
            else if([[[arr objectAtIndex:j]objectForKey:@"Entrance"]isEqual:@"Exchange.GetRate"]){
                [mlDic setObject:@"存款利率详情" forKey:@"Title"];
                FinancialInterest *cusChannel=[[FinancialInterest alloc]init];
                cusChannel.arrReturn=[[[[[[arr objectAtIndex:j] objectForKey:@"Items"] objectForKey:@"Item"] objectAtIndex:0] objectForKey:@"Properties"] objectForKey:@"Property"];
                
                rowHight=(cusChannel.arrReturn.count+1)*44;
                cusChannel.view.frame=CGRectMake(0, 32, 296, rowHight);
                [mlDic setObject:cusChannel forKey:@"content"];
                cusChannel=Nil;
                
            }
        }
        else if ([[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"railinfo"]){
            [mlDic setObject:@"列车" forKey:@"name"];
            
            if ([[[arr objectAtIndex:j]objectForKey:@"Entrance"]isEqual:@"RailInfo.GetRailRoute"]) {
                [mlDic setObject:@"发到站查询信息" forKey:@"Title"];
                TrainQuery *cusChannel=[[TrainQuery alloc]init];
                cusChannel.arrReturn=[[[arr objectAtIndex:j] objectForKey:@"Items"] objectForKey:@"Item"];
                cusChannel.isSelf=YES;
                cusChannel.strKey=self.txtContent.text;
                rowHight=138;
                cusChannel.view.frame=CGRectMake(0, 32, 296, rowHight);
                [mlDic setObject:cusChannel forKey:@"content"];
                cusChannel=Nil;
                
            }
            else if([[[arr objectAtIndex:j]objectForKey:@"Entrance"]isEqual:@"RailInfo.GetRailNumAndRoute"]){
                [mlDic setObject:@"车次查询信息" forKey:@"Title"];
                TrainTrainsHalf *cusChannel=[[TrainTrainsHalf alloc]init];
                cusChannel.arrReturn=[[[[arr objectAtIndex:j] objectForKey:@"Items"] objectForKey:@"Item"] objectAtIndex:0];
                
                rowHight=180;   
                cusChannel.view.frame=CGRectMake(0, 32, 296, rowHight);
                [mlDic setObject:cusChannel forKey:@"content"];
                cusChannel=Nil;
                
            }
            else if([[[arr objectAtIndex:j]objectForKey:@"Entrance"]isEqual:@"RailInfo.GetRailDetailRoute"]){
                [mlDic setObject:@"途经站信息" forKey:@"Title"];

                TrainStation *cusChannel=[[TrainStation alloc]init];
                cusChannel.arrReturn=[[[[arr objectAtIndex:j] objectForKey:@"Items"] objectForKey:@"Item"] objectAtIndex:0];
                cusChannel.isSelf=YES;
                rowHight=230;
                cusChannel.view.frame=CGRectMake(0, 32, 296, rowHight);
                [mlDic setObject:cusChannel forKey:@"content"];
                cusChannel=Nil;
                
            }

        }
        else if ([[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"horoscope"]) {
            [mlDic setObject:@"星座" forKey:@"name"];
            NSMutableArray *tempArray=[[[arr objectAtIndex:j] objectForKey:@"Items"] objectForKey:@"Item"];
            NSArray *tempList=[[[tempArray objectAtIndex:0] objectForKey:@"Properties"] objectForKey:@"Property"];
            NSString *temptext=[[tempList objectAtIndex:0] objectForKey:@"text"];
            [mlDic setObject:temptext forKey:@"Title"];

            if ([[[arr objectAtIndex:j]objectForKey:@"Entrance"]isEqual:@"Horoscope.GetSpecialHoroFortune"]) {
                ConstellationController *cusChannel=[[ConstellationController alloc]init];
                cusChannel.arrReturn=[[[arr objectAtIndex:j] objectForKey:@"Items"] objectForKey:@"Item"];
                cusChannel.isSelf=YES;
                cusChannel.view.frame=CGRectMake(0, 0, 296, 100);
                rowHight=cusChannel.table.contentSize.height;
                cusChannel.view.frame=CGRectMake(0, 32, 296, rowHight);
                [mlDic setObject:cusChannel forKey:@"content"];
                cusChannel=Nil;
            }
            else if([[[arr objectAtIndex:j]objectForKey:@"Entrance"]isEqual:@"Horoscope.GetMonthDateHoroscope"]||[[[arr objectAtIndex:j]objectForKey:@"Entrance"]isEqual:@"Horoscope.GetPairingExponent"]){
                ConstellationSingle *cusChannel=[[ConstellationSingle alloc]init];
                cusChannel.arrReturn=[[[arr objectAtIndex:j] objectForKey:@"Items"] objectForKey:@"Item"];
                ////                cusChannel.isSelf=YES;
                if ([[[arr objectAtIndex:j]objectForKey:@"Entrance"]isEqual:@"Horoscope.GetMonthDateHoroscope"]) {
                    rowHight=82;
                    cusChannel.view.frame=CGRectMake(0, 32, 296, rowHight);
                    
                }
                else{
                    rowHight=142;
                    cusChannel.isPair=YES;
                    cusChannel.view.frame=CGRectMake(0, 32, 296, rowHight);
                    
                    
                }
                [mlDic setObject:cusChannel forKey:@"content"];
                cusChannel=Nil;
                
            }
        }

        else if ([[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"local"]||
                 [[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"stock"]||
                 [[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"bankfinancing"]||
                 [[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"health"]||
                 [[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"legalinquiry"]||
                 [[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"tourism"]||
                 [[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"flightschedule"]||
                 [[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"cookbook"]) {
            NSURL *url;
             url = [NSURL URLWithString:[[[[[[[[arr objectAtIndex:j] objectForKey:@"Items"] objectForKey:@"Item"] objectAtIndex:0]objectForKey:@"Properties"] objectForKey:@"Property"] objectAtIndex:0] objectForKey:@"text"]];
            if (url==Nil) {
                 url = [NSURL URLWithString:[[[[[[[[[arr objectAtIndex:j] objectForKey:@"Items"] objectForKey:@"Item"] objectAtIndex:0]objectForKey:@"Properties"] objectForKey:@"Property"] objectAtIndex:0] objectForKey:@"text"]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
            }
            if ([[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"software"]) {
                 [mlDic setObject:@"软件" forKey:@"name"];
                [mlDic setObject:@"热门软件" forKey:@"Title"];
                
                 rowHight=68*9+60;
            }
            else if([[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"local"]){
                 [mlDic setObject:@"商家" forKey:@"name"];
                [mlDic setObject:@"商家信息" forKey:@"Title"];
                 url = [NSURL URLWithString:[[NSString stringWithFormat:@"%@",[Common Coordinate:[[[[[[[[arr objectAtIndex:j] objectForKey:@"Items"] objectForKey:@"Item"] objectAtIndex:0]objectForKey:@"Properties"] objectForKey:@"Property"] objectAtIndex:0] objectForKey:@"text"]]]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
//                NSLog(@"%@",url);
                 rowHight=75*6;
            }
            else if([[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"stock"]){
                [mlDic setObject:@"股票" forKey:@"name"];
                [mlDic setObject:@"股票动态" forKey:@"Title"];
                rowHight=287;
            }
            else if([[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"bankfinancing"]){
                [mlDic setObject:@"理财" forKey:@"name"];
                [mlDic setObject:@"金融理财" forKey:@"Title"];
                rowHight=74*6-30;
            }
            else if([[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"health"]){
                [mlDic setObject:@"健康" forKey:@"name"];
                [mlDic setObject:@"健康咨询" forKey:@"Title"];
                rowHight=74*6-80;
            }
            else if([[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"legalinquiry"]){
                [mlDic setObject:@"法律" forKey:@"name"];
                [mlDic setObject:@"法律咨询咨询" forKey:@"Title"];
                rowHight=74*7;
            }
            else if([[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"tourism"]){
                [mlDic setObject:@"旅游" forKey:@"name"];
                [mlDic setObject:@"旅游产品" forKey:@"Title"];
               
                rowHight=74*7;
            }
            else if([[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"flightschedule"]){
                [mlDic setObject:@"航班" forKey:@"name"];
                [mlDic setObject:@"航 班" forKey:@"Title"];
                
                rowHight=74*7;
            }
            else if([[[arr objectAtIndex:j]objectForKey:@"name"]isEqual:@"cookbook"]){
                [mlDic setObject:@"美食" forKey:@"name"];
                [mlDic setObject:@"美食专家" forKey:@"Title"];
                
                rowHight=74*7;
            }
            UIWebView *webContent=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 296,rowHight)];
            webContent.delegate = self;
            webContent.alpha=0.9999;
            //                [webContent setScalesPageToFit:YES];
            [webContent sizeToFit];
            [(UIScrollView *)[[webContent subviews] objectAtIndex:0] setBounces:NO];
            NSURLRequest *request = [NSURLRequest requestWithURL:url];
            [webContent loadRequest:request];
//            webContent.layer.borderWidth = 1;
//            webContent.layer.borderColor = [[UIColor grayColor] CGColor];
            [mlDic setObject:webContent forKey:@"content"];
            webContent=Nil;
            rowHight=rowHight-32;
        }
              if (rowHight>0) {
            [mlArr addObject:mlDic];
            [arrHight addObject:[NSString stringWithFormat:@"%f",rowHight+67]];
        }
        mlDic=Nil;
    }
    if (mlArr.count>0) {
        [arrCellContent addObject:mlArr];
        [arrCellHight addObject:arrHight];
    }
    else{
        [self NetHelp];
    }
    arrHight=Nil;
    mlArr=Nil;
     arr=Nil;
    [self TableReloadData];
//    NSLog(@"%@",arrCellContent);
}
-(void)requestFailed:(ASIHTTPRequest*)request{
    
}
//获取文件路径方法
- (NSString *)getFilePath {
    NSArray *segments = [NSArray arrayWithObjects:NSHomeDirectory(),@"Documents",@"useName.plist", nil];
    return [NSString pathWithComponents:segments];
}

-(void)BackButton{
    UIButton *btnBack=[[DetectionSystemVersion alloc]BackButton];
    [btnBack addTarget:self action:@selector(BackReturn:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithCustomView:btnBack];
    self.navigationItem.leftBarButtonItem=backItem;
}
-(void)ShareButton{
//    UIControl *btnBack=[[UIControl alloc]initWithFrame:CGRectMake(0, 0, 41, 29)];
//    [btnBack addTarget:self action:@selector(ShareButton:) forControlEvents:UIControlEventTouchUpInside];
//    UIImageView* Backbg=[[UIImageView alloc]init];
//    Backbg.image=[UIImage imageNamed:@"fenxiang"];
//    [btnBack addSubview:Backbg];
//    UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithCustomView:btnBack];
//       if ([[DetectionSystemVersion alloc]Version]) {
//        Backbg.frame=CGRectMake(5, 0, 36, 29);
//       
//    }
//    else{
//        Backbg.frame=CGRectMake(0, 0, 36, 29);
//       
//    }
//    
    
    UIButton *btnMessage=[[UIButton alloc]init];
    [btnMessage setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
     [btnMessage addTarget:self action:@selector(ShareButton:) forControlEvents:UIControlEventTouchUpInside];
    [btnMessage setImage:[UIImage imageNamed:@"fenxiang"] forState:UIControlStateNormal];
    btnMessage.frame=CGRectMake(0, 0, 36, 29);

//    if ([[DetectionSystemVersion alloc]Version]) {
//        btnMessage.frame=CGRectMake(0, 0, 36, 29);
//        
//    }
//    else{
//        btnMessage.frame=CGRectMake(5, 0, 36, 29);
//        
//    }
 UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithCustomView:btnMessage];
//    backItem.contentEdgeInsets = UIEdgeInsetsMake(0,8, 0, 0);
    self.navigationItem.rightBarButtonItem=backItem;
}
#pragma mark 导航栏按钮事件
-(void)BackReturn:(id)sender{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)ShareButton:(id)sender{
    NSString *message = @"我正在使用百事搜手机客户端，它能听懂您的话，只需您说话，商家、出行、休闲、娱乐、百科等信息，百事搜快速帮您查，快免费下载体验吧";
    NSArray *postItems = @[message];
    UIActivityViewController *activityVC = [[UIActivityViewController alloc]
                                            initWithActivityItems:postItems
                                            applicationActivities:nil];
    activityVC.excludedActivityTypes = @[UIActivityTypePrint, UIActivityTypeCopyToPasteboard,
                                         UIActivityTypeAssignToContact,UIActivityTypeSaveToCameraRoll];
    [self presentViewController:activityVC animated:YES completion:nil];
//    activityVC=Nil;
//    message=Nil;
//    postItems=Nil;
}

-(void)SetAllView{
    self.navigationItem.titleView=[DetectionSystemVersion SetBarTitle:@"百事搜"];
   
    self.tabel.separatorStyle=UITableViewCellSeparatorStyleNone;
    self.tabelDown.separatorStyle=UITableViewCellSeparatorStyleNone;
    isHideView=YES;
    NSString *initString = [[NSString alloc] initWithFormat:@"appid=%@",APPID ];
    _iFlyRecognizerView = [[IFlyRecognizerView alloc] initWithOrigin:CGPointMake(20, 180) initParam:initString];
    _iFlyRecognizerView.delegate = self;
    UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc]
                                             initWithTarget:self
                                             action:@selector(TapDown:)];
    [tapRecognizer setDelegate:self];
    [self.imgDown addGestureRecognizer:tapRecognizer];
    UIPanGestureRecognizer *recognizer = [[UIPanGestureRecognizer alloc]
                                          initWithTarget:self action:@selector(handleDown:)];
	[recognizer setMaximumNumberOfTouches:1];
    [recognizer setDelegate:self];
    [self.imgDown addGestureRecognizer:recognizer];
    
    

}

-(void)TapDown:(UITapGestureRecognizer *)sender{
    if (isHideView) {
        [self ShowPick:self.vieDown];
        isHideView=NO;
    }
    else{
    [self HidePick:self.vieDown];
        isHideView=YES;
    }
}

-(void)handleDown:(UIPanGestureRecognizer *)paramSender{
//     UIView *view = self.vieDown ;
//    if(paramSender.state == UIGestureRecognizerStateBegan) {
//        // remember where the pan started
//        _panGestureOrigin = view.frame.origin;
//        self.panDirection=MainSearchPanDirectionNone;
//	}
//    
//    if(self.panDirection==MainSearchPanDirectionNone) {
//        CGPoint translatedPoint = [paramSender translationInView:view];
//        if(translatedPoint.x > 0) {
//            self.panDirection = MainSearchPanDirectionUp;
//            
//        }
//        else if(translatedPoint.x < 0) {
//            self.panDirection = MainSearchPanDirectionDown;
//            
//        }
//    }
//    if((self.menuState == MenuSearchStateOpen && self.panDirection == MainSearchPanDirectionUp)
//       || (self.menuState == MenuSearchStateOpen && self.panDirection == MainSearchPanDirectionDown)) {
//        self.panDirection = MainSearchPanDirectionNone;
//        return;
//    }
//
//    
//    if(self.panDirection == MainSearchPanDirectionUp) {
//        [self handleUpPan:paramSender];
//    } else if(self.panDirection == MainSearchPanDirectionDown) {
//        [self handleDownPan:paramSender];
//    }
    if ( self.menuState==MenuSearchStateClosed) {
        if (isOver==YES) return;
        [self ShowPick:self.vieDown];
        isHideView=NO;
 
    }
    else{
        if (isOver==YES) return;
          [self HidePick:self.vieDown];
        isHideView=YES;

    }
//    if (paramSender.state != UIGestureRecognizerStateEnded && paramSender.state != UIGestureRecognizerStateFailed){
//        
//        CGPoint location = [paramSender locationInView:paramSender.view.superview];
//        self.vieDown.center = location;
//    }
//  
}
- (void) handleUpPan:(UIPanGestureRecognizer *)recognizer {
    if( self.menuState == MenuSearchStateClosed) return;
    
    UIView *view = self.vieDown;
    
    CGPoint translatedPoint = [recognizer translationInView:view];
    CGPoint adjustedOrigin = self.panGestureOrigin;
    translatedPoint = CGPointMake(adjustedOrigin.x + translatedPoint.x,
                                  adjustedOrigin.y + translatedPoint.y);
    
    translatedPoint.y = MAX(0, 0);
    translatedPoint.y = MIN(0, -50);
    if(self.menuState == MenuSearchStateOpen) {
        // menu is already open, the most the user can do is close it in this gesture
        translatedPoint.x = MIN(translatedPoint.x, 0);
    } else {
        // we are opening the menu
        translatedPoint.x = MAX(translatedPoint.x, 0);
    }
    
    [self setCenterViewControllerOffset:translatedPoint.x];
    
    if(recognizer.state == UIGestureRecognizerStateEnded) {
        CGPoint velocity = [recognizer velocityInView:view];
        CGFloat finalX = translatedPoint.x + (.35*velocity.x);
        CGFloat viewWidth = view.frame.size.width;
        
        if(self.menuState == MenuSearchStateClosed) {
            BOOL showMenu = (finalX > viewWidth/2) || (finalX > 20/2);
            if(showMenu) {
                self.panGestureVelocity = velocity.x;
                [self setMenuState:MenuSearchStateOpen];
            } else {
                self.panGestureVelocity = 0;
//                [self setCenterViewControllerOffset:0 animated:YES completion:nil];
            }
        } else {
            BOOL hideMenu = (finalX > adjustedOrigin.x);
            if(hideMenu) {
                self.panGestureVelocity = velocity.x;
                [self setMenuState:MenuSearchStateClosed];
            } else {
                self.panGestureVelocity = 0;
//                [self setCenterViewControllerOffset:adjustedOrigin.x animated:YES completion:nil];
            }
        }
        
        self.panDirection = MainSearchPanDirectionNone;
	}
}

- (void) handleDownPan:(UIPanGestureRecognizer *)recognizer {
//    if(!self.rightMenuViewController && self.menuState == MFSideMenuStateClosed) return;
//    
//    UIView *view = [self.centerViewController view];
//    
//    CGPoint translatedPoint = [recognizer translationInView:view];
//    CGPoint adjustedOrigin = panGestureOrigin;
//    translatedPoint = CGPointMake(adjustedOrigin.x + translatedPoint.x,
//                                  adjustedOrigin.y + translatedPoint.y);
//    
//    translatedPoint.x = MAX(translatedPoint.x, -1*self.rightMenuWidth);
//    translatedPoint.x = MIN(translatedPoint.x, self.leftMenuWidth);
//    if(self.menuState == MFSideMenuStateLeftMenuOpen) {
//        // don't let the pan go less than 0 if the menu is already open
//        translatedPoint.x = MAX(translatedPoint.x, 0);
//    } else {
//        // we are opening the menu
//        translatedPoint.x = MIN(translatedPoint.x, 0);
//    }
//    
//    [self setCenterViewControllerOffset:translatedPoint.x];
//    
//	if(recognizer.state == UIGestureRecognizerStateEnded) {
//        CGPoint velocity = [recognizer velocityInView:view];
//        CGFloat finalX = translatedPoint.x + (.35*velocity.x);
//        CGFloat viewWidth = view.frame.size.width;
//        
//        if(self.menuState == MFSideMenuStateClosed) {
//            BOOL showMenu = (finalX < -1*viewWidth/2) || (finalX < -1*self.rightMenuWidth/2);
//            if(showMenu) {
//                self.panGestureVelocity = velocity.x;
//                [self setMenuState:MFSideMenuStateRightMenuOpen];
//            } else {
//                self.panGestureVelocity = 0;
//                [self setCenterViewControllerOffset:0 animated:YES completion:nil];
//            }
//        } else {
//            BOOL hideMenu = (finalX < adjustedOrigin.x);
//            if(hideMenu) {
//                self.panGestureVelocity = velocity.x;
//                [self setMenuState:MFSideMenuStateClosed];
//            } else {
//                self.panGestureVelocity = 0;
//                [self setCenterViewControllerOffset:adjustedOrigin.x animated:YES completion:nil];
//            }
//        }
//	}
}
- (void) setCenterViewControllerOffset:(CGFloat)xOffset {
//    CGRect frame = self.vieDown.frame;
//    
//    frame.origin.x = xOffset;
//    self.vieDown.frame = frame;
//    
//    if(!self.menuSlideAnimationEnabled) return;
//    
//    if(xOffset > 0){
//        [self alignLeftMenuControllerWithCenterViewController];
//        [self setRightSideMenuFrameToClosedPosition];
//    } else if(xOffset < 0){
//        [self alignRightMenuControllerWithCenterViewController];
//        [self setLeftSideMenuFrameToClosedPosition];
//    } else {
//        [self setLeftSideMenuFrameToClosedPosition];
//        [self setRightSideMenuFrameToClosedPosition];
//    }
}

#pragma mark -
#pragma mark - Center View Controller Movement

//- (void)setCenterViewControllerOffset:(CGFloat)offset animated:(BOOL)animated completion:(void (^)(void))completion {
//    [self setCenterViewControllerOffset:offset additionalAnimations:nil
//                               animated:animated completion:completion];
//}
//
//- (void)setCenterViewControllerOffset:(CGFloat)offset
//                 additionalAnimations:(void (^)(void))additionalAnimations
//                             animated:(BOOL)animated
//                           completion:(void (^)(void))completion {
//    void (^innerCompletion)() = ^ {
//        if(completion) completion();
//    };
//    
//    if(animated) {
//        CGFloat centerViewControllerXPosition = ABS(self.vieDown.frame.origin.x);
//        CGFloat duration = [self animationDurationFromStartPosition:centerViewControllerXPosition toEndPosition:offset];
//        
//        [UIView animateWithDuration:duration animations:^{
//            [self setCenterViewControllerOffset:offset];
//            if(additionalAnimations) additionalAnimations();
//        } completion:^(BOOL finished) {
//            innerCompletion();
//        }];
//    } else {
//        [self setCenterViewControllerOffset:offset];
//        if(additionalAnimations) additionalAnimations();
//        innerCompletion();
//    }
//}

#pragma mark -
#pragma mark - UIGestureRecognizerDelegate

//- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
//    NSLog(@"代理");
//    if([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]] &&
//       self.menuState != MenuSearchStateClosed) return YES;
//    
//    if([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
////        if([gestureRecognizer.view isEqual:[self.centerViewController view]] &&
////           [self centerViewControllerPanEnabled]) return YES;
////        
////        if([gestureRecognizer.view isEqual:self.menuContainerView] &&
////           [self sideMenuPanEnabled]) return YES;
//    }
//    
//    return NO;
//}
//
//- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
//    return YES;
//}

#pragma mark UITextFile 代理

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    
    if ((range.length!=1&&[text isEqualToString:@"\n"])) {
        if (self.txtContent.text.length>0) {
           [self GetDatas:self.txtContent.text];
            [self.txtContent resignFirstResponder];
        }
        return NO;
    }
    else{
        
        return YES;
    }
}
- (void)textViewDidChange:(UITextView *)textView{
    
//    if (14+self.txtContent.contentSize.height>48) {
//        self.vieMessage.frame=CGRectMake(0, self.view.frame.size.height-48, 320,48);
//    }
//    else{
//    CGSize sizeFrame;
//    NSString *str=textView.text;
//    if (str.length!=0) {
//        sizeFrame =[str sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(197, MAXFLOAT) lineBreakMode:NSLineBreakByWordWrapping];
//    }
    float vieHight=13+self.txtContent.contentSize.height;
    self.vieMessage.frame=CGRectMake(0, self.view.frame.size.height-vieHight, 320, vieHight);
//    }
//    NSLog(@"%f",sizeFrame.height);
    
}

//判断键盘高度
-(void)keyboardWillShow:(NSNotification*)notification{
    NSDictionary *info=[notification userInfo];
    CGSize kbSize=[[info objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue].size;
    [self ViewAnimatios:kbSize.height];
}
-(void)keyboardWillHide:(NSNotification*)notification{
    [self ViewAnimatios:0];
}

#pragma mark TscrollView viewHeight
-(void)ViewAnimatios:(int)viewHeight{
    
    [UIView beginAnimations:@"ResizeForKeyboard" context:(__bridge void *)((UIView *)self.view)];
    [UIView setAnimationDuration:0.3f];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:nil];
    self.view.frame = CGRectMake(0.0f, -viewHeight+keyHight, self.view.frame.size.width,self.view.frame.size.height);
    //    vieNewfav.frame=CGRectMake(0, self.view.frame.size.height-60, 320, 140);
    [UIView commitAnimations];
}

-(void)SetMessageView{
    UIImage *buttonNo = [UIImage imageNamed:@"shurukuang"];
    UIImage *stretchNo = [buttonNo stretchableImageWithLeftCapWidth:0 topCapHeight:buttonNo.size.height/2];
    self.imgText.image=stretchNo;
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
           // Return the number of sections.
    int num;
    if ([tableView isEqual:self.tabelDown]) {
        num=1;
    }
    else{
//         num=arrReturn.count;
        
        num=arrCellContent.count;
//        NSLog(@"行数%d",num);
    }
    return num;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    int num;
    if ([tableView isEqual:self.tabelDown]) {
        num=3;
    }
    else{
//        NSLog(@"%d",arrReturn.count);
        num=1;
    }
    return num;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   
    if ([tableView isEqual:self.tabelDown]) {
        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        }
        cell.selectionStyle=UITableViewCellSelectionStyleGray;
        NSDictionary *dic=[[NSMutableArr sharedInstance].arrCuston objectAtIndex:indexPath.row];
        UIImageView *img=[[UIImageView alloc]initWithFrame:CGRectMake(15, 15, 47, 47)];
        img.image=[UIImage imageNamed:@"chuanliantouxiang"];
        [img setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[dic objectForKey:@"picurl"]]] placeholderImage:[UIImage imageNamed:@"chuanliantouxiang"]];
        [cell.contentView addSubview:img];
        
        UILabel *lab=[[UILabel alloc]initWithFrame:CGRectMake(75, 15, 320-75, 25)];
        lab.text=[NSString stringWithFormat:@"%@",[dic objectForKey:@"title"]];
        lab.textColor=[UIColor blackColor];
        lab.backgroundColor=[UIColor clearColor];
        lab.font=[UIFont systemFontOfSize:14];
        [cell.contentView addSubview:lab];
        
        UILabel *labDetial=[[UILabel alloc]initWithFrame:CGRectMake(75, 45, 320-75, 20)];
        labDetial.text=[NSString stringWithFormat:@"%@",[dic objectForKey:@"text"]];
        labDetial.textColor=[UIColor lightGrayColor];
        labDetial.backgroundColor=[UIColor clearColor];
        labDetial.font=[UIFont systemFontOfSize:13];
        [cell.contentView addSubview:labDetial];
        if (indexPath.row!=0) {
            UIImageView *imgLine=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 1)];
            imgLine.image=[UIImage imageNamed:@"fengexian"];
            [cell.contentView addSubview:imgLine];

        }
        dic=nil;
        return cell;

    }
    else{
        static NSString *CellIden = @"CustomCell";
         CustomCell *cusCell =(CustomCell*) [tableView cellForRowAtIndexPath:indexPath];
//        CustomCell *cusCell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIden];
        if (!cusCell) {
            cusCell = [[[NSBundle mainBundle] loadNibNamed:CellIden owner:self options:nil] objectAtIndex:0];
            cusCell.backgroundColor=[UIColor clearColor];
            UILongPressGestureRecognizer *longPressGestureRecognizer=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(cellLongPress:)];
            longPressGestureRecognizer.numberOfTouchesRequired = 1;
            longPressGestureRecognizer.minimumPressDuration = 0.5;
            [cusCell addGestureRecognizer:longPressGestureRecognizer];
           

        }
//         NSLog(@"%@",arrCellContent);
//        NSLog(@"%@",[arrCellContent objectAtIndex:indexPath.row]);
        if ([[arrCellContent objectAtIndex:indexPath.section] isKindOfClass:[NSString class]]) {
            [cusCell.vieCell removeFromSuperview];
            UIButton *btnMessage=[[UIButton alloc]init];
            [btnMessage setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            btnMessage.titleLabel.numberOfLines=0;
            btnMessage.titleLabel.font=[UIFont systemFontOfSize:15];
            UIImage *buttonNo = [UIImage imageNamed:@"btnShuRuKuang"];
            UIImage *stretchNo = [buttonNo stretchableImageWithLeftCapWidth:30 topCapHeight:24];
            CGSize btnSize=[DetectionSystemVersion String:[arrCellContent objectAtIndex:indexPath.section] Width:246 Font:15];
            btnMessage.frame=CGRectMake(296-50-btnSize.width, 0, btnSize.width+45, btnSize.height+30);
            btnMessage.contentEdgeInsets = UIEdgeInsetsMake(3,20, 0, 25);
            [btnMessage setBackgroundImage:stretchNo forState:UIControlStateNormal];
            [btnMessage setTitle:[arrCellContent objectAtIndex:indexPath.section] forState:UIControlStateNormal];
            
            [cusCell.vieBack addSubview:btnMessage];
 
        }
       
        else{
//            无搜索结果
            NSArray *arr=[arrCellContent objectAtIndex:indexPath.section];
            NSMutableDictionary *mlDic=[arr objectAtIndex:[[arrCurrentRow objectAtIndex:indexPath.section] integerValue]];
            if ([[[arr objectAtIndex:0] objectForKey:@"name"] isEqual:@"互联网帮助"] ) {
//                [cusCell.vieCell removeFromSuperview];
                NetHelp *netHelp=[[NetHelp alloc]init];
                netHelp.strQuery=[[arr objectAtIndex:0] objectForKey:@"Title"];
                netHelp.view.frame=CGRectMake(0, 0, 296, 118);
                [cusCell.vieBack addSubview:netHelp.view ];
                [self addChildViewController:netHelp];
                cusCell.vieBack.frame=CGRectMake(cusCell.vieCell.frame.origin.x, 0, cusCell.vieBack.frame.size.width, 118);
                cusCell.vieBack.backgroundColor=[UIColor clearColor];
            }
            else{
        for (int i=0; i<arr.count; i++) {
            UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(i*67, 9, 67, 24)];
            [btn setTitle:[[arr objectAtIndex:i] objectForKey:@"name"] forState:UIControlStateNormal];
            [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            if (i==[[arrCurrentRow objectAtIndex:indexPath.section] integerValue]) {
                 [btn setBackgroundImage:[UIImage imageNamed:@"searchRowOption"] forState:UIControlStateNormal];
            }
            else{
                 [btn setBackgroundImage:[UIImage imageNamed:@"searchRowOptionUn"] forState:UIControlStateNormal];
            }
            [btn addTarget:self action:@selector(PressRow:) forControlEvents:UIControlEventTouchUpInside];
            btn.titleLabel.font=[UIFont systemFontOfSize:16];
            btn.tag=300+indexPath.section*4+i;
            btn.titleEdgeInsets = UIEdgeInsetsMake(0,19, 0, 0);
          
            UIImageView *img=[[UIImageView alloc]initWithFrame:CGRectMake(8, 4, 15, 15)];
            [img setClipsToBounds:YES];
            [img setContentMode:UIViewContentModeScaleAspectFit];
            img.image=[UIImage imageNamed:[[arr objectAtIndex:i] objectForKey:@"name"]];
            [btn addSubview:img];
            [cusCell.vieBack addSubview:btn];
        }
        if ([[mlDic objectForKey:@"content"]  isKindOfClass:[UIViewController class]]) {
            UIViewController *control=(UIViewController *)[mlDic objectForKey:@"content"];
            [cusCell.vieCell addSubview:control.view];
            [self addChildViewController:control];
        }
        else{
//            NSLog(@"%@  第%d个",[mlDic objectForKey:@"content"],indexPath.section);
            
            [cusCell.vieCell addSubview:[mlDic objectForKey:@"content"]];

        }
        cusCell.labTitle.text=[mlDic objectForKey:@"Title"];
        cusCell.vieCell.layer.borderWidth = 1;
        cusCell.vieCell.layer.cornerRadius=5;
         cusCell.vieCell.layer.masksToBounds=YES;
        cusCell.vieCell.layer.borderColor = [[UIColor colorWithHexString:@"0xdadada"] CGColor];
        UIImageView *imgOptionLine=[[UIImageView alloc]initWithFrame:CGRectMake(0, 33, 296, 3)];
        imgOptionLine.image=[UIImage imageNamed:@"searchRowOptionUnder"];
        [cusCell.vieBack addSubview:imgOptionLine];
        }
        }
        cusCell.selectionStyle=UITableViewCellSelectionStyleGray;

//        cusCell.textLabel.text=@"自定义";
       
        return cusCell;
    }
   
   
}
-(void)PressRow:(UIButton *)button{
    [arrCurrentRow setObject:[NSString stringWithFormat:@"%d",(button.tag-300)%4] atIndexedSubscript:(button.tag-300)/4];
    [self TableReloadData];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([tableView isEqual:self.tabelDown]) {
        [self HidePick:self.vieDown];
        isHideView=YES;
         NSDictionary *dic=[[NSMutableArr sharedInstance].arrCuston objectAtIndex:indexPath.row];
        if ([[dic objectForKey:@"mode"] integerValue] ==0 ) {
            self.strSearch=[dic objectForKey:@"query"];
            [self GetDatas:self.strSearch];
           
        }
        else{
           self.strSearch=[dic objectForKey:@"hyperlinkurl"];
            if ([[dic objectForKey:@"query"]  isEqual:@""]) {
                self.isUrl=3;
            }
            else{
                self.isUrl=2;
            }
            [self WebUrl];
        }
        dic=nil;
    }
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
-(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    float num=44.0;
    if ([tableView isEqual:self.tabelDown]) {
        num=77.0;
    }
    else{
        num=[[[arrCellHight objectAtIndex:indexPath.section] objectAtIndex:[[arrCurrentRow objectAtIndex:indexPath.section] integerValue]]floatValue];
//        NSLog(@"%f",num);
    }
    return num;

}
-(float)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (![tableView isEqual:self.tabelDown]) {
        if (section==0) {
            return 35;
        }
        
    }
    return 0;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *result;
    result=[[UIView alloc]init];
    result.backgroundColor=[UIColor clearColor];
    return result;
}
-(float)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (![tableView isEqual:self.tabelDown]) {
        return 30;
    }
    return 0;
}
-(UIView *) tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *result;
    result=[[UIView alloc]init];
    result.backgroundColor=[UIColor clearColor];
    return result;

}
- (void)cellLongPress:(UIGestureRecognizer *)recognizer{
//    NSLog(@"%@",recognizer.view);
    if (recognizer.state == UIGestureRecognizerStateBegan) {
        
//        CGPoint location = [recognizer locationInView:self.tabel];
//        NSIndexPath *indexPath = [self.tabel indexPathForRowAtPoint:location];
//        NSLog(@"%f %f",location.x,location.y);
        CustomCell *cell = (CustomCell *)recognizer.view;
        longIndexPath= [self.tabel indexPathForCell:cell];
        if ([[arrCellContent objectAtIndex:longIndexPath.section] isKindOfClass:[NSString class]]) {
            UIAlertView *alr=[[UIAlertView alloc]initWithTitle:@"操作" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"分享",@"删除",@"再次发送",@"清空所有", nil];
            [alr show];
        }
        else{
            UIAlertView *alr=[[UIAlertView alloc]initWithTitle:@"操作" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"删除",@"清空所有", nil];
            [alr show];
        }
       
        //这里把cell做为第一响应(cell默认是无法成为responder,需要重写canBecomeFirstResponder方法)
//        [cell becomeFirstResponder];
//        
//        UIMenuItem *itCopy = [[UIMenuItem alloc] initWithTitle:@"复制" action:@selector(handleCopyCell:)];
//        UIMenuItem *itDelete = [[UIMenuItem alloc] initWithTitle:@"删除" action:@selector(handleDeleteCell:)];
//        UIMenuController *menu = [UIMenuController sharedMenuController];
//        [menu setMenuItems:[NSArray arrayWithObjects:itCopy, itDelete,  nil]];
//        [menu setTargetRect:cell.frame inView:self.tabel];
//        [menu setMenuVisible:YES animated:YES];
        
    }
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    NSString *str=[alertView buttonTitleAtIndex:buttonIndex];
    if ([str isEqual:@"分享"]) {
        [self ShareButton:Nil];
    }
    else if([str isEqual:@"删除"]){
//        NSDictionary *arrMessage=[arrCellContent objectAtIndex:longIndexPath.section];
//        NSLog(@"%ld %d",(long)longIndexPath.section ,longIndexPath.row);
        [arrCellContent removeObjectAtIndex:longIndexPath.section];
        [arrCellHight removeObjectAtIndex:longIndexPath.section];
        [arrCurrentRow removeObjectAtIndex:longIndexPath.section];
//        NSLog(@"%d %d %d",arrCellContent.count ,arrCurrentRow.count,arrCellHight.count);
        [self TableReloadData];
//        [self.tabel deleteRowsAtIndexPaths:[NSArray arrayWithObject:longIndexPath] withRowAnimation:UITableViewRowAnimationFade];

    }
    else if([str isEqual:@"再次发送"]){
        [self GetDatas:[arrCellContent objectAtIndex:longIndexPath.section]];
    }
    else if([str isEqual:@"清空所有"]){
        [arrCellContent removeAllObjects];
        [arrCellHight removeAllObjects];
        [arrCurrentRow removeAllObjects];
        [self TableReloadData];
    }
    else if([str isEqual:@"查询"]){
        [self sendSMS:strNumber recipientList:arrMessageContent];
        strNumber=Nil;
        arrMessageContent=Nil;
        
    }
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark 动画
-(void)HidePick:(UIView *)vieBounced {
    isOver=YES;
    [UIView animateWithDuration:0.8
                     animations:^(void) {
                          vieBounced.frame=CGRectMake(0, vieBounced.frame.origin.y-self.tabelDown.frame.size.height, vieBounced.frame.size.width, vieBounced.frame.size.height);
                         //                         vieBounced.frame = CGRectMake(0, self.view.frame.size.height, 104, (self.view.frame.size.height-117-8)/3);
                     } completion:^(BOOL finished) {
                         self.menuState=MenuSearchStateClosed;
                         isOver=NO;
                                             }];
    
}
-(void)ShowPick:(UIView *)vieBounced{
    isOver=YES;
    //    const CGRect toFrame = (CGRect){arrowPoint, 104, ((self.view.frame.size.height-117-8)/3)};
    [UIView animateWithDuration:0.4
                          delay:0
                        options:UIViewAnimationOptionLayoutSubviews
                     animations:^(void){
                         vieBounced.frame=CGRectMake(0, vieBounced.frame.origin.y+self.tabelDown.frame.size.height, vieBounced.frame.size.width, vieBounced.frame.size.height);
                         //                         vieBounced.frame = toFrame;
                     }
     
                     completion:^(BOOL finished) {
                         self.menuState=MenuSearchStateOpen;
                         isOver=NO;
                         //                                  [image removeFromSuperview];
                     }];
    
}


- (IBAction)PressIFly:(id)sender {
    [self.txtContent resignFirstResponder];
    [_iFlyRecognizerView setParameter:@"grammarID" value:_grammarID];
    
    // 参数设置
    [_iFlyRecognizerView setParameter:@"domain" value:@"iat"];
    //    [_iFlyRecognizerView setParameter:@"vad_bos" value:@"500"];
    [_iFlyRecognizerView setParameter:@"sample_rate" value:@"16000"];
    [_iFlyRecognizerView setParameter:@"vad_eos" value:@"1800"];
    [_iFlyRecognizerView setParameter:@"vad_bos" value:@"6000"];
    [_iFlyRecognizerView setParameter:@"asr_ptt" value:@"0"];
    [_iFlyRecognizerView start];

}
#pragma mark -
#pragma mark IFlySynthesizerControlDelegate methods
- (void)onResult:(IFlyRecognizerView *)iFlyRecognizerView theResult:(NSArray *)resultArray{
    NSMutableString *result = [[NSMutableString alloc] init];
    NSDictionary *dic = [resultArray objectAtIndex:0];
    for (NSString *key in dic) {
        [result appendFormat:@"%@",key];
    }
    self.txtContent.text = [NSString stringWithFormat:@"%@",result];
    //    NSLog(@"成功了吗%@",resultArray);
}
- (void)onEnd:(IFlyRecognizerView *)iFlyRecognizerView theError:(IFlySpeechError *) error{
    //    NSLog(@"错误了嘛%@",error);
}
//-(void)StatrWebView:(NSString *)strUrl viewBack:(UIView *)vie{
//    webContent=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 300, 200)];
//    webContent.delegate = self;
//    [webContent setScalesPageToFit:YES];
//    [(UIScrollView *)[[webContent subviews] objectAtIndex:0] setBounces:NO];
//    [vie addSubview:webContent];
//    NSURL *url = [NSURL URLWithString:strUrl];
//    NSURLRequest *request = [NSURLRequest requestWithURL:url]; [webContent loadRequest:request];
//}
#pragma mark 网页代理
- (void)webViewDidStartLoad:(UIWebView *)webView{
   
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
    
    NSString *meta = [NSString stringWithFormat:@"document.getElementsByName(\"viewport\")[0].content = \"width=%f, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no\"", webView.frame.size.width];
    [webView stringByEvaluatingJavaScriptFromString:meta];

//    NSLog(@"%f",webView.frame.size.height);
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    if (webView.alpha<1.0) {
        webView.alpha=1.0;
        return YES;
    }
    
    NSString *strUrl=[ NSString stringWithFormat:@"%@",request.URL];
    strUrl=[strUrl stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
   
    if ([strUrl hasPrefix:@"tel:"]) {
        
    }
    else if ([strUrl hasPrefix:@"sms:"])
    {
        [self GetMessage:[strUrl componentsSeparatedByString:@"|"]];
        
    }
    else{
        WebController *webCon=[[WebController alloc]init];
        webCon.requestUrl=request;
         [self.navigationController pushViewController:webCon animated:YES];
    }
//    if (request.URL) {
//        <#statements#>
//    }
   
//    NSLog(@"哈哈");
    return NO;
}

//解析短信内容
-(void)GetMessage:(NSArray *)arr{
    
     NSRange rang;
    NSString *strTitle;
    NSString *strMessage;
    //        [self sendSMS:@"CZ601988" recipientList:arr];
    for (int i=0; i<arr.count; i++) {
        NSString *str=[arr objectAtIndex:i];
        if ([str hasPrefix:@"sms:"]) {
            rang=[str rangeOfString:@"sms:"];
            str=[str substringFromIndex:rang.location+rang.length];
            arrMessageContent=[[NSArray alloc]initWithObjects:str, nil];
           
        }
        else if([str hasPrefix:@"content:"]){
            rang=[str rangeOfString:@"content:"];
            strNumber=[str substringFromIndex:rang.location+rang.length];
            }
        else if([str hasPrefix:@"alerttitle:"]){
            rang=[str rangeOfString:@"alerttitle:"];
            strTitle=[str substringFromIndex:rang.location+rang.length];

        }
        else if([str hasPrefix:@"alertcontent:"]){
            rang=[str rangeOfString:@"alertcontent:"];
            strMessage=[NSString stringWithFormat:@"%@\n\n（点播资费1元/条）详询118114转理财 （只支持电信手机）",[str substringFromIndex:rang.location+rang.length]];
            
        }
    }
    UIAlertView *alr=[[UIAlertView alloc]initWithTitle:strTitle message:strMessage delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"查询", nil];
    [alr show];
    strTitle=Nil;
    strMessage=Nil;
}
- (void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSArray *)recipients
{
    
    MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
    
    if([MFMessageComposeViewController canSendText]){
        controller.body = bodyOfMessage;
        controller.recipients = recipients;
        controller.messageComposeDelegate = self;
        [self presentViewController:controller animated:YES completion:Nil];
    }
}
// 处理发送完的响应结果
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
    [self dismissViewControllerAnimated:YES completion:Nil];
    [self ShowHUD];
    if (result==MessageComposeResultCancelled) {
        HUD.labelText=@"取消了发送";
        HUD.customView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"HUDProblem"]];
        HUD.mode = MBProgressHUDModeCustomView;
//        NSLog(@"取消");
        
    }
    else if(result==MessageComposeResultSent){
        HUD.customView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"HUDTrue"]];
        HUD.mode = MBProgressHUDModeCustomView;
         HUD.labelText=@"发送成功";
        
    }
    else{
        HUD.labelText=@"发送失败";
        HUD.customView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"HUDFlase"]];
        HUD.mode = MBProgressHUDModeCustomView;
       
    }
    [HUD hide:YES afterDelay:1];
}
- (IBAction)PressSend:(id)sender {
    
//    strKeyWord=self.txtContent.text;
//    [self BtnRow:self.txtContent.text];
    [self GetDatas:self.txtContent.text];
    [self.txtContent resignFirstResponder];
}
-(void)BtnRow:(NSString *)string{
//    NSLog(@"闯过了%@",string);
    [arrCellContent addObject:string];
    CGSize btnSize=[DetectionSystemVersion String:self.txtContent.text Width:246 Font:15];
    NSArray *arrHight;
    if (btnSize.height<17.9) {
        arrHight=[[NSArray alloc]initWithObjects:[NSString stringWithFormat:@"%f",17.9+30], nil];
    }
    else{
       arrHight=[[NSArray alloc]initWithObjects:[NSString stringWithFormat:@"%f",btnSize.height+30], nil];
    }
//    NSArray *
//    NSLog(@"%f",btnSize.height);
    [arrCurrentRow addObject:[NSString stringWithFormat:@"%d",0]];
    [arrCellHight addObject:arrHight];
  
    [self TableReloadData];

}
-(void)ShowHUD{
    HUD = [[MBProgressHUD alloc] initWithView:self.view];
    HUD.delegate = self;
    HUD.labelText = @"";
    [self.view addSubview:HUD];
    [HUD show:YES];
}
#pragma mark MBProgressHUDDelegate methods
//日常对话
-(NSString *)DailyConversation:(NSString *) greeting{
    NSString *answer=[[NSString alloc] init];
    NSString *greetPath=[[NSBundle mainBundle]pathForResource:@"greeting" ofType:@"plist"];
    NSDictionary *allGreetings=[[NSDictionary alloc]init];
    allGreetings=[NSDictionary dictionaryWithContentsOfFile:greetPath];
    answer=[allGreetings objectForKey:greeting];
    return answer;
}

- (void)hudWasHidden:(MBProgressHUD *)hud {
    // Remove HUD from screen when the HUD was hidded
    [HUD removeFromSuperview];
    HUD = nil;
}
@end
